package com.ifcreate.infowell.common.util;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.Date;

/**
 * @Author chenzedeng
 * @Email yustart@foxmail.com
 * @Create 2020-10-29 11:38 上午
 */
public class LongToDateStrSerializer extends JsonSerializer<Long> {

    @Override
    public void serialize(Long l, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (l != null) {
            String format = DateUtil.format(new Date(l), "yyyy-MM-dd");
            jsonGenerator.writeString(format);
        } else {
            jsonGenerator.writeNull();
        }
    }
}
